
/*
 * Copyright 2002-2017 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 *版权所有2002-2017原作者。
 *
 *根据Apache许可证2.0版许可（“许可证”）；
 *除非符合许可证的规定，否则您不得使用此文件。
 *您可以在以下网址获取许可证副本：
 *
 *https://www.apache.org/licenses/LICENSE-2.0
 *
 *除非适用法律要求或书面同意，软件
 *根据许可证进行的分发是在“按原样”的基础上进行的，
 *无任何明示或暗示的保证或条件。
 *有关管理权限的特定语言，请参阅许可证和
 *许可证下的限制。
 */

package org.springframework.scripting;

import java.io.IOException;

import org.springframework.lang.Nullable;

/**
 * Script definition interface, encapsulating the configuration
 * of a specific script as well as a factory method for
 * creating the actual scripted Java {@code Object}.
 *
 * @author Juergen Hoeller
 * @author Rob Harrop
 * @since 2.0
 * @see #getScriptSourceLocator
 * @see #getScriptedObject
 */
/**
 *脚本定义接口，封装配置
 *的特定脚本以及工厂方法
 *创建实际的脚本化Java｛@code Object｝。
 *
 *@作者于尔根·霍勒
 *@作者Rob Harrop
 *@自2.0起
 *@参见#getScriptSourceLocator
 *@参见#getScriptedObject
 */
public interface ScriptFactory {

	/**
	 * Return a locator that points to the source of the script.
	 * Interpreted by the post-processor that actually creates the script.
	 * <p>Typical supported locators are Spring resource locations
	 * (such as "file:C:/myScript.bsh" or "classpath:myPackage/myScript.bsh")
	 * and inline scripts ("inline:myScriptText...").
	 * @return the script source locator
	 * @see org.springframework.scripting.support.ScriptFactoryPostProcessor#convertToScriptSource
	 * @see org.springframework.core.io.ResourceLoader
	 */
	/**
	 *返回一个指向脚本源的定位器。
	 *由实际创建脚本的后处理器进行解释。
	 *<p>典型的支持定位器是Spring资源位置
	 *（例如“file:C:/myScript.bsh”或“classpath：myPackage/myScript.bsh”）
	 *和内联脚本（“inline:myScriptText…”）。
	 *@返回脚本源定位器
	 *@参见org.springframework.scripting.support.ScriptFactoryPostProcessor#convertToScriptSource
	 *@参见org.springframework.core.io.ResourceLoader
	 */
	String getScriptSourceLocator();

	/**
	 * Return the business interfaces that the script is supposed to implement.
	 * <p>Can return {@code null} if the script itself determines
	 * its Java interfaces (such as in the case of Groovy).
	 * @return the interfaces for the script
	 */
	/**
	 *返回脚本应该实现的业务接口。
	 *＜p＞如果脚本本身确定，则可以返回｛@code null｝
	 *它的Java接口（例如Groovy）。
	 *@返回脚本的接口
	 */
	@Nullable
	Class<?>[] getScriptInterfaces();

	/**
	 * Return whether the script requires a config interface to be
	 * generated for it. This is typically the case for scripts that
	 * do not determine Java signatures themselves, with no appropriate
	 * config interface specified in {@code getScriptInterfaces()}.
	 * @return whether the script requires a generated config interface
	 * @see #getScriptInterfaces()
	 */
	/**
	 *返回脚本是否需要配置接口
	 *为其生成。通常情况下
	 *不确定Java签名本身，没有适当的
	 *｛@code getScriptInterface（）｝中指定的配置接口。
	 *@return脚本是否需要生成配置接口
	 *@参见#getScriptInterface（）
	 */
	boolean requiresConfigInterface();

	/**
	 * Factory method for creating the scripted Java object.
	 * <p>Implementations are encouraged to cache script metadata such as
	 * a generated script class. Note that this method may be invoked
	 * concurrently and must be implemented in a thread-safe fashion.
	 * @param scriptSource the actual ScriptSource to retrieve
	 * the script source text from (never {@code null})
	 * @param actualInterfaces the actual interfaces to expose,
	 * including script interfaces as well as a generated config interface
	 * (if applicable; may be {@code null})
	 * @return the scripted Java object
	 * @throws IOException if script retrieval failed
	 * @throws ScriptCompilationException if script compilation failed
	 */
	/**
	 *用于创建脚本化Java对象的工厂方法。
	 *<p>鼓励实现缓存脚本元数据，例如
	 *生成的脚本类。请注意，可以调用此方法
	 *并且必须以线程安全的方式实现。
	 *@param scriptSource要检索的实际scriptSource
	 *来自的脚本源文本（从不｛@code null｝）
	 *@param actualInterfaces要公开的实际接口，
	 *包括脚本接口以及生成的配置接口
	 *（如果适用；可以是{@code null}）
	 *@返回脚本化的Java对象
	 *如果脚本检索失败，@throws IOException
	 *如果脚本编译失败，@throws ScriptCompilationException
	 */
	@Nullable
	Object getScriptedObject(ScriptSource scriptSource, @Nullable Class<?>... actualInterfaces)
			throws IOException, ScriptCompilationException;

	/**
	 * Determine the type of the scripted Java object.
	 * <p>Implementations are encouraged to cache script metadata such as
	 * a generated script class. Note that this method may be invoked
	 * concurrently and must be implemented in a thread-safe fashion.
	 * @param scriptSource the actual ScriptSource to retrieve
	 * the script source text from (never {@code null})
	 * @return the type of the scripted Java object, or {@code null}
	 * if none could be determined
	 * @throws IOException if script retrieval failed
	 * @throws ScriptCompilationException if script compilation failed
	 * @since 2.0.3
	 */
	/**
	 *确定脚本化Java对象的类型。
	 *<p>鼓励实现缓存脚本元数据，例如
	 *生成的脚本类。请注意，可以调用此方法
	 *并且必须以线程安全的方式实现。
	 *@param scriptSource要检索的实际scriptSource
	 *来自的脚本源文本（从不｛@code null｝）
	 *@返回脚本化Java对象的类型，或｛@code null｝
	 *如果无法确定
	 *如果脚本检索失败，@throws IOException
	 *如果脚本编译失败，@throws ScriptCompilationException
	 *@自2.0.3起
	 */
	@Nullable
	Class<?> getScriptedObjectType(ScriptSource scriptSource)
			throws IOException, ScriptCompilationException;

	/**
	 * Determine whether a refresh is required (e.g. through
	 * ScriptSource's {@code isModified()} method).
	 * @param scriptSource the actual ScriptSource to retrieve
	 * the script source text from (never {@code null})
	 * @return whether a fresh {@link #getScriptedObject} call is required
	 * @since 2.5.2
	 * @see ScriptSource#isModified()
	 */
	/**
	 *确定是否需要刷新（例如通过
	 *ScriptSource的｛@code isModified（）｝方法）。
	 *@param scriptSource要检索的实际scriptSource
	 *来自的脚本源文本（从不｛@code null｝）
	 *@return是否需要新的｛@link#getScriptedObject｝调用
	 *@自2.5.2起
	 *@参见ScriptSource#isModified（）
	 */
	boolean requiresScriptedObjectRefresh(ScriptSource scriptSource);

}
